#include "regx52.h"
#include "STC89C5xRC-rdp.h"
#include "datatype.h"
#include "bit.h"
#include "delay.h"

#include "LCD1602.h"
#include <string.h>

int_8 *string_1 = "Hitachi HD44780 LCD controller";
int_8 *string_2 = "Grayson Zheng";

void test_1(void)
{
	lcd1602_show_char(0, 0, 'G');
	lcd1602_show_char(0, 5, '&');
	lcd1602_show_string(1, 2, "Grayson Zheng");
	delay_1s();
	lcd1602_clear_screen();
	lcd1602_show_number(0, 9, 666);
	lcd1602_show_hex(1, 0, 0x1234);
	delay_1s();
	lcd1602_clear_screen();
	lcd1602_show_number(0, 9, -321);
	lcd1602_show_bin(1, 0, 0xABCD);
	delay_1s();
	lcd1602_clear_screen();
}

void test_2(void)
{
	uint_8 i;
	for (i = 0; i < strlen(string_1) - 16; i++) {
		lcd1602_shift_left();
		delay_xms(500);
	}
	delay_1s();
	for (i = 0; i < strlen(string_1) - 16; i++) {
		lcd1602_shift_right();
		delay_xms(500);
	}
	delay_1s();
}

void setup(void)
{
	/* put your setup code here, to run once: */
	lcd1602_init();
	test_1();
}

void main(void)
{
	setup();

	lcd1602_show_string(0, 0, string_1);
	lcd1602_show_string(1, 2, string_2);
	while(TRUE) {
		/* put your main code here, to run repeatedly: */
		test_2();
	}
}